package com.huajin.gateway.nmap.controller;

import java.util.List;
import java.util.Map;

import com.huajin.gateway.util.PageUtils;
import com.huajin.gateway.util.Query;
import com.huajin.gateway.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.huajin.gateway.nmap.domain.ScanconfigDO;
import com.huajin.gateway.nmap.service.ScanconfigService;


/**
 * 扫描配置表
 *
 * @author huajin
 * @email 1992lcg@163.com
 * @date 2018-11-01 14:32:09
 */

@Controller
@RequestMapping("/nmap/scanconfig")
public class ScanconfigController {
    @Autowired
    private ScanconfigService scanconfigService;

    @GetMapping()
    String Scanconfig() {
        return "nmap/scanconfig/scanconfig";
    }

    @ResponseBody
    @GetMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<ScanconfigDO> scanconfigList = scanconfigService.list(query);
        int total = scanconfigService.count(query);
        PageUtils pageUtils = new PageUtils(scanconfigList, total);
        return pageUtils;
    }


    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    public R save(@RequestBody ScanconfigDO scanconfig) {
        if (scanconfigService.save(scanconfig) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    public R update(@RequestBody ScanconfigDO scanconfig) {
        scanconfigService.update(scanconfig);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ResponseBody
    public R remove(Integer id) {
        if (scanconfigService.remove(id) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @PostMapping("/batchRemove")
    @ResponseBody
    public R remove(@RequestParam("ids[]") Integer[] ids) {
        scanconfigService.batchRemove(ids);
        return R.ok();
    }

}
